#include <stdio.h>
#include <string.h>
#include <malloc.h>

int countStr(const char *str,const char *lookStr);

void printChars(const char* str);

/*
void strsplit(char *str,char sep) {
    //char *str = src;
    int count =sizeof(str)/sizeof(str[0]);
    printf("size=%d",count);
    char dst[ ]="";
    int step=0;
    //int len=0;
    for(int i=0;i<count;i++){
        if(str[i]==sep){
          strncpy(dst,str,i-step);

            step=i;
            printf("parts%d :%s\n",i,dst);
            memset(dst,0,sizeof(dst));
        }
    }
*/

   /* strncat(dst,str+step,strlen(str)-step);
    printf("parts%d :%s\n",step,dst);*/

//}



int main() {
    //char str[]="welcome to china,welcome to guandong,welcome to donggun,welcome to zmt";
   // char *looup="come";
  //  char *res=strchr(str,'t');//to china,welcome to guandong,welcome to donggun,welcome to zmt
   // printf("result:%s\n",res);
   /* char *rc=strpbrk(str,"come");//elcome to china,welcome to guandong,welcome to donggun,welcome to zmt
    printf("%s\n",rc);*/
  /*
    int i=countStr(str,looup);
    printf("times:%d",i);*/
    char content[]="welcome to costa rica";
    char splitter =' ';

    int size =sizeof(content)/sizeof(content[0]);
    char dst[]="";
    int step=0;
    //char ch=' ';
    char tem[]="";
    for(int i=0;i<size;i++){
        if(content[i]==splitter){
            strncat(tem,content+step,i-step);
            step=i;
            printf("parts%d :%s\n",step,tem);
            memset(tem,0,sizeof(tem));
        }
    }

    strncat(tem,content+step,strlen(content)-step);
    printf("parts%d :%s\n",step,tem);

    return 0;
}



void printChars(const char* str) {

       int len=strlen(str)/sizeof(str[0]);
       for(int i=0;i<len;i++){
           printf("%c\n",str[i]);
       }
}

int countStr(const char *str,const char *lookStr) {
    char *c1=strstr(str, lookStr);//come:come to china,welcome to guandong,welcome to donggun,welcome to zmt
    int i=0;
    while (c1!=NULL){
        printf("result:%s\n",c1);
        c1++;
        i++;
        c1=strstr(c1, lookStr);
    }

   // printf("times:%d\n",i);
    return i;
}

